package com.audi.core.common;


import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.commons.lang.StringUtils;

/**
 * 字符串截取
 * @author hujh
 *
 */
public class StringAbbreviate extends SimpleTagSupport {

	private String value;
	private Integer maxLength;
	
	@Override
	public void doTag() throws JspException, IOException {
	
		JspWriter out=getJspContext().getOut();
		
		out.write(process());
		
		super.doTag();
	}
	
	
	private String process(){
		if (maxLength==null ||maxLength<4)
			maxLength=4;
		
		if (this.value==null)
			return "";					
		else
			return StringUtils.abbreviate(this.value, this.maxLength);
		
	}


	public String getValue() {
		return value;
	}


	public void setValue(String value) {
		this.value = value;
	}


	public Integer getMaxLength() {
		return maxLength;
	}


	public void setMaxLength(Integer maxLength) {
		this.maxLength = maxLength;
	}
	
	
	
}
